//
//  UIBarButtonItem+Extensions.swift
//  gc微博
//
//  Created by 高聪 on 16/11/7.
//  Copyright © 2016年 高聪. All rights reserved.
//

import UIKit

extension UIBarButtonItem {
    
    /// 创建 UIBarButtonItem
    ///
    /// - parameter title:    title
    /// - parameter fontSize: fontSize,默认16号
    /// - parameter target:   target
    /// - parameter action:   action
    /// - parameter isBack:   是否是返回按钮，如果是 加上箭头
    ///
    /// - returns: UIBarButtonItem
    convenience init(title:String, fontSize:CGFloat = 16, target:Any? , action:Selector, isBack:Bool = false) {
        let btn: UIButton = UIButton.cz_textButton(title, fontSize: fontSize, normalColor: UIColor.darkGray , highlightedColor: UIColor.orange )
        if isBack {
            let imageName = "navigationbar_back_withtext"
             btn.setImage(UIImage(named:imageName), for: UIControlState.normal)
             btn.setImage(UIImage(named:imageName), for: UIControlState.highlighted)
            btn.sizeToFit()
        }
        
        
        btn.addTarget(target, action: action, for: .touchUpInside)
       
        // self.init 实例化 uibarbuttonitem
        self.init(customView:btn)
    }
    
}
